﻿using Digitalmes.Core.Common.Interfaces;
using Digitalmes.Infrastructure.Unique;
using Yitter.IdGenerator;

namespace Digitalmes.Infrastructure;

public static class UniqueServiceCollectionExtensions
{
    public static IServiceCollection AddUniqueSetup(this IServiceCollection services)
    {
        // 雪花Id
        YitIdHelper.SetIdGenerator(new IdGeneratorOptions
        {
            WorkerId = 1, // 机器码 全局唯一
            WorkerIdBitLength = 1, // 机器码位长 默认值6，取值范围 [1, 19]
            SeqBitLength = 6, // 序列数位长 默认值6，取值范围 [3, 21]（建议不小于4，值越大性能越高、Id位数也更长）
        });

        services.AddSingleton<IUnique, UniqueGenerator>();

        return services;
    }
}
